package com.erdos.hyt.mall.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import springfox.documentation.annotations.ApiIgnore;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashSet;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * Created by Jett Tian on 17-03-13.
 */
@Configuration
@EnableSwagger2 //Enable swagger 2.0 spec
@ComponentScan("com.erdos.hyt.mall.controller")
public class SwaggerConfiguration {
	/*@Bean
	public SecurityScheme apiKey() {
	       return new ApiKey("access_token", "accessToken", "header");
	}*/

    private Predicate<String> mallPaths() {
        return regex("/mall/.*");
    }

    @Bean
    public Docket mallApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("mall-api")
                .apiInfo(mallInfo())
                .select()
                .paths(mallPaths())
                .build()
                .directModelSubstitute(LocalDateTime.class,Date.class)
                .directModelSubstitute(LocalDate.class, java.sql.Date.class)
                .ignoredParameterTypes(ApiIgnore.class)
                .enableUrlTemplating(false);
    }
    private ApiInfo mallInfo() {
        Contact contact = new Contact("刘荣", "", "");
        return new ApiInfoBuilder()
                .title("商城相关 API")
                .description("商城 API")
                .contact(contact)
                .version("1.0")
                .build();
    }


    private HashSet<String> produecetypes(){
        HashSet <String> hs = new HashSet<String>();
        hs.add(MediaType.APPLICATION_JSON_VALUE);
      /*  hs.add(MediaType.TEXT_HTML_VALUE); 目前返回数据都为Json格式 */
        return hs;
    }
}